#include <stdio.h>
#include <pthread.h>
#include <unistd.h>


void* func(void* agr)
{
	printf("agr = %d\n",(int)agr);
	printf("pid =%d tid = %lu\n", getpid(),pthread_self());
	pthread_exit("线程已被回收");

}

int main()
{
	//创建五个线程
	pthread_t tid[5];
	int ret;
	int i;
	void* retval;
	for(i = 0; i < 5; i++ )
	{
		ret = pthread_create(&tid[i], NULL, func, (void *)i);
	}
	sleep(10);

	//回收线程
	for(i = 0; i < 5; i++)
	{

		pthread_join(tid[i],&retval);
		printf("retval = %s",(char*)retval);
	}
	return 0;
}
